package org.bao.demo.rabbitmq;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName Consumer
 * @Description 消息消费者
 * @Author bai
 * @Date 2021/7/21 0:08
 * @Version 1.0
 **/
public class Consumer {

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = MqFactory.getConnection();

        Channel channel = connection.createChannel();

        // 消息成功接收
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println(new String(message.getBody()));
        };

        CancelCallback cancelCallback = (consumerTag) -> {
            System.out.println("消息消费中断");
        };

        channel.basicConsume(Common.QUEUE_NAME, true, deliverCallback, cancelCallback);


    }
}
